package com.hzjy.manage.controller;

import com.hzjy.common.core.controller.BaseController;
import com.hzjy.common.core.domain.AjaxResult;
import com.hzjy.common.core.page.TableDataInfo;
import com.hzjy.manage.service.impl.HzjyDelistServiceImpl;
import com.hzjy.manage.service.impl.HzjyProductServiceImpl;
import com.hzjy.manage.vo.HzjyDelist;
import com.hzjy.manage.vo.HzjyDelistDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api("摘牌清单")
@RestController
@RequestMapping("/manage/audit_delist")
public class AuditDelistController extends BaseController {

    @Autowired
    private HzjyDelistServiceImpl hzjyDelistService;
    @Autowired
    private HzjyProductServiceImpl hzjyProductService;

    @ApiOperation("获取摘牌清单集合")
    @PreAuthorize("@ss.hasPermi('manage:audit_delist:list')")
    @PostMapping("/list")
    public TableDataInfo auditDelistList() {
        startPage();
        List<HzjyDelistDTO> hzjyDelistDTOList = hzjyDelistService.selectAuditDelistList();
        return getDataTable(hzjyDelistDTOList);
    }

    @ApiOperation("删除摘牌")
    @PreAuthorize("@ss.hasPermi('manage:audit_delist:delete')")
    @PostMapping("/delete")
    public AjaxResult deleteDelis(@RequestBody HzjyDelist hzjyDelist){
        hzjyDelistService.deleteHzjyDelistById(hzjyDelist.getDelistId());
        return AjaxResult.success();
    }

    @ApiOperation("上传备案")
    @PreAuthorize("@ss.hasPermi('manage:audit_delist:update')")
    @PostMapping("/updateDelis")
    public AjaxResult updateDelis(@RequestBody HzjyDelist hzjyDelist){
        hzjyDelist.setStatus(10);
        hzjyDelistService.updateHzjyDelist(hzjyDelist);
        hzjyProductService.selectProductInfo(hzjyDelist.getProductId());
        return AjaxResult.success();
    }
}
